<template>
    <div style="background: #e1dfdf">
            <van-tabs route v-model="active" v-if="goodInfo&&bGood">
                <van-tab replace title="商品" name="info" :to="{name:'info',query:{goodInfo}}"></van-tab>
                <van-tab
                    replace
                    title="详情"
                    name="detail"
                    :to="{name:'detail',query:{data:goodInfo.detail}}"
                ></van-tab>
                <van-tab
                    replace
                    title="评价"
                    name="comment"
                    :to="{name:'comment',query:{data:goodInfo}}"
                ></van-tab>
            </van-tabs>

            <router-view />


        <van-goods-action v-if="bGood">
            <van-goods-action-icon icon="chat-o" text="客服" />
            <van-goods-action-icon icon="cart-o" text="购物车" />
            <van-goods-action-icon icon="shop-o" text="店铺" />
            <van-goods-action-button type="warning" text="加入购物车" />
            <van-goods-action-button type="danger" text="立即购买" />
        </van-goods-action>
    </div>
</template>

<script>
import axios from "axios";
import {
    mapState,
    mapGetters,
    mapActions,
    mapMutations,
    createNamespaceHelpers
} from "vuex";
import { M_DETAIL_GOOD, A_DETAIL_INFO } from "../../store/types";
export default {
    name: "",
    data() {
        return {
            active: "info"
            // goodInfo: null
        };
    },
    async mounted() {
        let id = this.$route.params.id;
        // this.goodInfo = this.$route.query.goodInfo;
        await this[A_DETAIL_INFO]({ type: "goods", params: { _id: id } });
        await this[M_DETAIL_GOOD](true);
        // console.log(goodInfo)
    },
    methods: {
        ...mapMutations("detail", [M_DETAIL_GOOD]),
        ...mapActions("detail", [A_DETAIL_INFO])
    },
    components: {},
    // async beforeRouteEnter(to, from, next) {
    //     let id = to.params.id;
    //     let res = await axios("/api/goods?_id=" + id);
    //     to.query.goodInfo = res.data.data[0];

    //     next();
    // },

    computed: mapState("detail", ["bGood", "goodInfo"])
};
</script>

<style scoped>
</style>
